<template>
  <div class="gongshi">
    <el-dialog title="批示意见/办理提示" :visible.sync="noticeVisible" width="95%">
      <notice :noticePersonId="noticePersonId" :step="selStep"></notice>
      <div slot="footer" class="dialog-footer" style="overflow:hidden">
        <el-button @click.native="noticeVisible = false" style="float:right">关闭</el-button>
      </div>
    </el-dialog>
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item>公示</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxnoborder">
      <div :style="'height:'+tableHeight+'px'">
        <el-scrollbar style="height: calc(100% + 16px);">
            <el-radio-group v-model="departmentName" @change="steponeRadioChange4" style="margin:15px 15px 0" class="pointRadio">
              <el-radio-button v-if="mangeDep.indexOf('干部一处')>-1||mangeDep.indexOf('干部监督处')>-1" label="干部一处">
                <el-badge v-if="num1>0" :value="num1" class="item">干部一处事项</el-badge>
                <span v-else>干部一处事项</span>
              </el-radio-button>
              <el-radio-button v-if="mangeDep.indexOf('干部二处')>-1||mangeDep.indexOf('干部监督处')>-1" label="干部二处">
                <el-badge v-if="num2>0" :value="num2" class="item">干部二处事项</el-badge>
                <span v-else>干部二处事项</span>
              </el-radio-button>
              <el-radio-button v-if="mangeDep.indexOf('干部三处')>-1||mangeDep.indexOf('干部监督处')>-1" label="干部三处">
                <el-badge v-if="num3>0" :value="num3" class="item">干部三处事项</el-badge>
                <span v-else>干部三处事项</span>
              </el-radio-button>
            </el-radio-group>
          <div style="margin:15px">
          <el-table
            v-loading="listloading"
            border
            size="small"
            :data="tableData4"
            tooltip-effect="dark"
            @selection-change="handleSelectionChange4">
            <el-table-column
              type="selection"
              width="55">
            </el-table-column>
            <el-table-column
              label="序号"
              type="index"
              width="50">
            </el-table-column>
            <el-table-column
              prop="realName"
              label="姓名"
              width="80">
            </el-table-column>
            <el-table-column
              prop="unitName"
              width="150"
              label="选任岗位单位"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="jobName"
              width="150"
              label="选任岗位职务"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="jobLevel"
              label="选任岗位职级"
              width="120"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              prop="dateto"
              label="公示时间"
              width="180"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column label="附件">
              <template slot-scope="scope">
                <el-link type="primary"
                v-for="item of scope.row.files"
                :key="item.id"
                :href="$http.defaults.baseURL+$http.defaults.selectionAPI+'api/gen/file/download?id='+item.id"
                target="_blank">{{item.fileName}}.{{item.fileType}}</el-link>
              </template>
            </el-table-column>
            <el-table-column label="有无举报" width="150">
              <template slot-scope="scope">
                <span v-if="scope.row.jubao===1">有</span>
                <span v-else>无</span>
              </template>
            </el-table-column>
            <el-table-column label="是否影响任命" width="150">
              <template slot-scope="scope">
                <span v-if="scope.row.yingxiang===1">影响</span>
                <span v-else>不影响</span>
              </template>
            </el-table-column>
            <el-table-column
              label="办理提示、批示信息"
              width="160">
              <template slot-scope="scope">
                    <el-popover placement="bottom" width="600" trigger="hover">
                      <notice :noticePersonId="scope.row.personId" step="6"></notice>
                      <el-button size="small" slot="reference" type="primary" @click="showNotice(scope.row.personId)">查看详情</el-button>
                    </el-popover>
              </template>
            </el-table-column>
          </el-table>
          </div>
          <select-group :backflag="false" :selectData="selectData" :selectPerson="selectPerson2" :selApi="selApi" :selStep="selStep" @getList="getList4"></select-group>
        </el-scrollbar>
      </div>
    </section>
  </div>
</template>

<script>
import selectGroup from '../common/SelectGroup2'
import notice from '../common/Notice'
export default {
  name: 'gongshi',
  data () {
    return {
      listloading: false,
      tableHeight: 100,
      departmentCode: 1,
      departmentName: '干部一处',
      tableData4: [],
      selectData: {
        hjData: [
        ],
        szData: [
        ],
        cnData: [],
        yyData: []
      },
      selApi: 'api/selection/publicity/submitApprove',
      selStep: 6,
      selectPerson2: [], // 已退回
      num1: 0,
      num2: 0,
      num3: 0,
      noticePersonId: '',
      noticeVisible: false,
      mangeDep: []
    }
  },
  components: {
    selectGroup,
    notice
  },
  mounted () {
    this.mangeDep = localStorage.getItem('mangeDep')
    if (!this.mangeDep || this.mangeDep === '') {
      this.mangeDep = []
    }
    console.log('mangeDep' + this.mangeDep)
    let departmentCodes = []
    if (this.mangeDep.indexOf('干部一处') > -1) {
      departmentCodes.push(1)
    }
    if (this.mangeDep.indexOf('干部二处') > -1) {
      departmentCodes.push(2)
    }
    if (this.mangeDep.indexOf('干部三处') > -1) {
      departmentCodes.push(3)
    }
    if (this.mangeDep.indexOf('干部监督处') > -1) {
      departmentCodes = [1, 2, 3]
    }
    console.log('departmentCodes' + departmentCodes)
    this.departmentCode = departmentCodes[0]

    if (this.departmentCode === 1) {
      this.departmentName = '干部一处'
    }
    if (this.departmentCode === 2) {
      this.departmentName = '干部二处'
    }
    if (this.departmentCode === 3) {
      this.departmentName = '干部三处'
    }
    // 待公示 一处列表
    this.getList4()
    // resize
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  },
  methods: {
    showNotice (id) {
      this.noticePersonId = id
      this.noticeVisible = true
    },
    loadSelectData () {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=1`)
        .then(response => {
          if (response.data.success) {
            this.selectData.hjData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].unitName === '干部监督处' || response.data.result[i].unitName === this.departmentName) {
                this.selectData.hjData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/auth/getUsersByRole?roletype=2`)
        .then(response => {
          if (response.data.success) {
            this.selectData.szData = []
            for (let i = 0; i < response.data.result.length; i++) {
              if (response.data.result[i].roleName === 'ROLE_sizhang' || response.data.result[i].manageDep.indexOf(this.departmentName) > -1 || response.data.result[i].manageDep.indexOf('干部监督处') > -1) {
                this.selectData.szData.push(response.data.result[i])
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/home/getCommonlyOpinions?step=6`)
        .then(response => {
          if (response.data.success) {
            this.selectData.yyData = response.data.result
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getList4 () { // 已退回
      this.getNums()
      this.loadSelectData()
      this.listloading = true
      let url = this.$http.defaults.selectionAPI + 'api/selection/publicity/getApprove'
      // console.log(url)
      this.$http.get(url, {
        params: {
          departmentCode: this.departmentCode
        }
      }).then(res => {
        this.listloading = false
        console.log('get list4 succ:', res)
        if (res.data.success === true) {
          let rs = res.data.result
          let arr = []
          for (let i of rs) {
            arr.push({
              candidateUnit: i.candidateUnit,
              currentJob: i.currentJob,
              currentLevel: i.currentLevel,
              jobLevel: i.jobLevel,
              jobName: i.jobName,
              personId: i.personId,
              publicityBatchId: i.publicityBatchId,
              realName: i.realName,
              unitName: i.unitName,
              dateto: i.dateStart + '至' + i.dateEnd,
              files: i.files,
              jubao: i.tips,
              yingxiang: i.appointment
            })
          }
          this.tableData4 = arr
        } else {
          this.$message({
            message: '数据获取失败',
            type: 'error'
          })
        }
      })
    },
    steponeRadioChange4 () {
      console.log(this.departmentName)
      if (this.departmentName === '干部一处') {
        this.departmentCode = 1
        this.getList4()
      } else if (this.departmentName === '干部二处') {
        this.departmentCode = 2
        this.getList4()
      } else if (this.departmentName === '干部三处') {
        this.departmentCode = 3
        this.getList4()
      }
    },
    handleSelectionChange4 (val) { // 已退回
      console.log('table4 select val:', val)
      this.selectPerson2 = [...val]
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 165
      })
    },
    getNums () {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/statnum/publicity/getStatNum2`)
        .then(response => {
          if (response.data.success) {
            this.num1 = response.data.result.num1
            this.num2 = response.data.result.num2
            this.num3 = response.data.result.num3
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(function (error) {
          console.log(error)
        })
    }
  }
}
</script>
<style>
.gongshi .el-table--border td, .el-table--border th, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed{
  border-bottom:1px solid #95B8E7;
}
.gongshi .el-table td, .el-table th.is-leaf{
  border-right:1px solid #95B8E7;
}
.gongshi .wboxnoborder .el-table{
  border: #95B8E7 solid 1px;
}
.gongshi .wboxnoborder .el-table th{
  font-weight: normal;
  background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  text-align: center;
  border-right: #95B8E7 solid 1px;
  border-bottom: #95B8E7 solid 1px;
  min-height: 30px;
  line-height:30px;
}
.gongshi .wboxnoborder .el-table td, .el-table th{
  padding:0;
  font-size:var(--size14) !important;
  line-height: 20px;
  font-family: '宋体';
  text-align: center;
}
.gongshi .el-table__row{
  height: 50px;
}
</style>
<style scoped>
.gongshi {
  width: 100%;
  box-sizing: border-box;
}
.gongshi-tit {
  width: 100%;
  height: 50px;
  line-height: 50px;
  padding: 0 8px;
  box-sizing: border-box;
  font-size: 15px;
  font-weight: bolder;
}
.gongshi .wboxnoborder {
  padding: 0;
  width: 100%;
  background-color: #fff;
  margin: 0 10px;
  overflow: hidden;
}
</style>
